﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Http;
using Ross.EntityFramework;
using Ross.Service;
using Ross.Service.Dto;
using System.Web.Http.Results;

namespace Ross.Traning.Controllers
{
    [SimpleAuthenticationFilter]
    public class CommentsController : BaseApiController
    {
        [HttpPost]
        public JsonResult<ResultDto<bool>> Comment([FromBody] Service.Dto.Comments comm)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (CommentsService serv = new CommentsService(dbContextStr))
            {
                result = serv.Comment(comm);
            }
            return Json(result);
        }
        [HttpGet]
        public JsonResult<ResultDto<List<Service.Dto.Comments>>> GetList(string keywords = "", long userId = 0, long courseId = 0)
        {
            ResultDto<List<Service.Dto.Comments>> result = new ResultDto<List<Service.Dto.Comments>>();
            using (CommentsService serv = new CommentsService(dbContextStr))
            {
                result = serv.GetAllList(keywords, userId, courseId);
            }
            return Json(result);
        }
        [HttpPost]
        public JsonResult<ResultDto<bool>> Delete(long id)
        {
            ResultDto<bool> result = new ResultDto<bool>();
            using (CommentsService serv = new CommentsService(dbContextStr))
            {
                result = serv.Delete(id);
            }
            return Json(result);
        }

        
    }
}